import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class Movie {
    private static List<Movie> allMovies = new ArrayList<>();
    private String movieId;
    private String name;
    private String director;
    private String actor;
    private String introduction;
    private int duration;
    private double score;
    private String type;
    private boolean isShowing;

    public Movie(String name, String director, String actor, String introduction,
                 int duration, double score, String type) {
        this.movieId = "MOV_" + UUID.randomUUID().toString().substring(0, 6); // 自动生成ID
        this.name = name;
        this.director = director;
        this.actor = actor;
        this.introduction = introduction;
        this.duration = duration;
        this.score = score;
        this.type = type;
        this.isShowing = true;
    }

    public static void addToAllMovies(Movie movie) {
        allMovies.add(movie);
    }
    public static void removeFromAllMovies(Movie movie) {
        allMovies.remove(movie);
    }
    public static List<Movie> getAllMovies() {
        return allMovies;
    }
    public static Movie findMovie(String key) {
        for (Movie movie : allMovies) {
            if (movie.movieId.equals(key) || movie.name.equals(key)) {
                return movie;
            }
        }
        return null;
    }
    public static boolean isNameExists(String name) {
        for (Movie movie : allMovies) {
            if (movie.name.equals(name)) {
                return true;
            }
        }
        return false;
    }

    public String getMovieId() {
        return movieId;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getDirector() {
        return director;
    }
    public void setDirector(String director) {
        this.director = director;
    }
    public String getActor() {
        return actor;
    }
    public void setActor(String actor) {
        this.actor = actor;
    }
    public String getIntroduction() {
        return introduction;
    }
    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }
    public int getDuration() {
        return duration;
    }
    public void setDuration(int duration) {
        this.duration = duration;
    }
    public double getScore() {
        return score;
    }
    public void setScore(double score) {
        if (score >= 0 && score <= 10) {
            this.score = score;
        } else {
            System.out.println("评分必须在0-10分之间！");
        }
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public boolean isShowing() {
        return isShowing;
    }
    public void setShowing(boolean showing) {
        isShowing = showing;
    }
    @Override
    public String toString() {
        return "ID：" + movieId + "\n" + "名称：" + name + "\n" + "类型：" + type + " | 评分：" + score + "\n" + "导演：" + director + " | 主演：" + actor + "\n" + "时长：" + duration + "分钟 | 状态：" + (isShowing ? "已上映" : "未上映") + "\n" + "简介：" + introduction;
    }
}
